package com.neuedu.boot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.boot.entity.CheckItem;
import com.neuedu.boot.service.ICheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 检查项目 前端控制器
 * </p>
 *
 * @author 金山老师
 * @since 2024-04-01
 */
@RestController
@RequestMapping("/checkitem")
public class CheckItemController {

    @Autowired
    ICheckItemService checkItemService;


    /**
     * http://localhost:8080/checkItem/list
     * @param checkItem
     * @return
     */
    @RequestMapping("/list")
    public List<CheckItem> list(CheckItem checkItem) {

        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        return checkItemService.list(queryWrapper);
    }


    @RequestMapping("/page")
    public Page page(Page<CheckItem> page , CheckItem checkItem) {

        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        if(checkItem.getName()!= null && !"".equals(checkItem.getName().trim())){
            queryWrapper.like("name" ,checkItem.getName() );
        }
        return checkItemService.page(page ,queryWrapper);
    }

    @RequestMapping("/saveOrUpdate")
    public boolean  saveOrUpdate( @RequestBody CheckItem checkItem){
        return  checkItemService.saveOrUpdate(checkItem);
    }


    @RequestMapping("/removeById/{id}")
    public boolean  removeById(@PathVariable int id){
        return  checkItemService.removeById(id);
    }


    @RequestMapping("/getById/{id}")
    public CheckItem getById(@PathVariable  int id){
        return  checkItemService.getById(id);
    }
}
